<template>
  <el-form v-if="device.code.indexOf('CRT_RELAY_') === 0" label-position="left" :label-width="labelWidth">
    <el-form-item :label="$t('device.Direct')">
      <el-switch :value="device.mode === 7" :active-text="$t('device.Forword')" :inactive-text="$t('device.Reverse')"
        v-on:change="handleChangeMode($event)"></el-switch>
    </el-form-item>
  </el-form>
</template>
<script>
  import BaseManager from './BaseManager'
  import deviceAPI from '@/api/device/device'
  export default {
    name: 'CurtainManager',
    mixins: [BaseManager],
    data() {
      return {
        device: {
          mode: null
        }
      }
    },
    methods: {
      setValue(value) {
        this.device = Object.assign({}, value)
      },
      handleChangeMode(modeFlag) {
        const mode = modeFlag ? 7 : 8
        const vm = this
        deviceAPI.update({
          id: this.device.id,
          mode
        }).then((res) => {
          vm.device.mode = mode
          vm.$emit('input', device)
        })
      }
    }
  }

</script>
